﻿using log4net;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace SBarth.TheLionsShare
{
    public partial class Site : System.Web.UI.MasterPage
    {

        public static readonly ILog log = LogManager.GetLogger(typeof(Site));
        public enum WebPage : int { Home = 1, AboutUs = 2, Testimonials = 3, ContactUs = 4 };

        protected void Page_Load(object sender, EventArgs e)
        {
            log.Debug("Initialising ....");

            Response.Cache.SetCacheability(HttpCacheability.Public);
            Response.Cache.SetMaxAge(TimeSpan.FromDays(1));
            Response.Cache.SetExpires(DateTime.Now.AddDays(1));
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            //Page.ViewStateUserKey = Session.SessionID; // TODO: Seems to be causing stability issues
        }

        public void ShowActivePage(WebPage currentPage)
        {
            String[] navbuttons = new String[] { "lnkNavHome", "lnkNavAbout", "lnkNavTestimonials", "lnkNavContact" };
            String currentPageControl = "";

            switch (currentPage)
            {
                case WebPage.Home:
                    currentPageControl = "lnkNavHome";
                    break;
                case WebPage.AboutUs:
                    currentPageControl = "lnkNavAbout";
                    break;
                case WebPage.Testimonials:
                    currentPageControl = "lnkNavTestimonials";
                    break;
                case WebPage.ContactUs:
                    currentPageControl = "lnkNavContact";
                    break;
                default:
                    currentPageControl = "";
                    break;
            }

            foreach (string s in navbuttons)
            {
                WebControl ctl = (WebControl)this.FindControl(s);

                if (ctl != null)
                {
                    if (s == currentPageControl)
                    {
                        ctl.Attributes["class"] = "nav_active";
                    }
                    else
                    {
                        ctl.Attributes.Remove("class");
                    }
                }
            }
            

        }
    }
}